//
//  PhotoViewController.m
//  Four_Fit_New
//
//  Created by xalo on 16/7/20.
//  Copyright © 2016年 xmaz. All rights reserved.
//

#import "PhotoViewController.h"
#import "UserViewController.h"

@interface PhotoViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *cameraBtn;
@property (weak, nonatomic) IBOutlet UIButton *albunBtn;
@property (nonatomic, strong) UIImagePickerController *imagePick;   //添加相机
@end

@implementation PhotoViewController

- (UIImagePickerController *)imagePick {
    
    if (!_imagePick) {
        
        _imagePick = [[UIImagePickerController alloc]init];
        _imagePick.delegate = self;
        _imagePick.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    return _imagePick;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Unknown-1.png"] style:(UIBarButtonItemStylePlain) target:self action:@selector(leftAction:)];
}

//相机
- (IBAction)cameraBtn:(id)sender {
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
        self.imagePick.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:self.imagePick animated:YES completion:nil];
    }
}

//相册
- (IBAction)albunBtn:(id)sender {
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        
        self.imagePick.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:self.imagePick animated:YES completion:nil];
    }
}

- (void)leftAction:(UIBarButtonItem *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
